/*
 * Created on Dec 27, 2004
 */
package persistence.connection;


/**
 * @author Valter Camargo
 *
 */
public abstract aspect ConnectionComposition {

   /**
    * This attribute was put here to maintain the relationship between
    * the composition rules (represented by this aspect hierarchy) and
    * variable part (represented by ConnectionManager hierarchy). 
    */
   private ConnectionManager connectionManager;

	
   /**
	* These pointcuts are extension points.
   * These make part of the framework fix part 
   */
   public abstract pointcut openConnection();
   public abstract pointcut closeConnection();
   
   public ConnectionComposition(){
   try
   {

    Class c = Class.forName(getNameOfConnectionVariabilitiesClass());
    connectionManager = (ConnectionManager)c.newInstance();
    
   }
	catch(ClassNotFoundException e){
		System.out.println("CATCH: ConnectionComposition 1: " + e.getMessage());
	}
	catch(IllegalAccessException e){
		System.out.println("CATCH: ConnectionComposition 2: " + e.getMessage());
	}
	catch(InstantiationException e){
		System.out.println("CATCH: ConnectionComposition 3: " + e.getMessage());
	}
	catch(Exception e){
		System.out.println("CATCH: ConnectionComposition 4: " + e.getMessage());
		
	}
   	
   }
   
   public abstract String getNameOfConnectionVariabilitiesClass();
   
   before() : openConnection()
   {
     try
     {
    	  	connectionManager.ConnectDB();
     	    System.out.println("*** After execute the ConnectDB method ****");	  	
     
     }
    catch(Exception e)
    {
      System.out.println ("CATCH: ConnectionComposition : OpenConnection: " + e.getMessage());
    }
   }
   
   after():closeConnection(){

     try
     {
       System.out.println("The method closeDB() will be called for database:  " + ConnectionManager.getConnection().getCatalog());	
       connectionManager.DisconnectDB();
       System.out.println("*** After execute the CloseDB() ****");
     }
     catch(Exception e)
     {
       System.out.println ("CATCH: ConnectionComposition: closeConnection: Error Message : " + e.getMessage());
     }

   }

   
	
}
